﻿@using ZX.Tools
@using ZX.Model
@model Document_Library

@{
    ViewBag.Title = "公司文档库-编辑-指效OA";
}
<link href="~/Static/styles/theme/default/all.css" rel="stylesheet" />
<link href="~/Static/styles/theme/zui/css/min.css" rel="stylesheet" />
<link href="~/Static/js/jquery/chosen/chosen.min.css" rel="stylesheet" />
<link href="~/Static/js/layui/css/layui.css" rel="stylesheet" />
<link href="/Static/styles/bootstrap.min.css" rel="stylesheet" />
<link href="~/Static/js/layer/need/layer.css" rel="stylesheet" />
<script src="/Static/js/jquery/jquery-1.11.1.min.js"></script>
<script src="/Static/js/jquery/form/min.js"></script>
<script src="~/Static/js/Validform_v5.3.2_min.js"></script>
<script src="~/Static/js/jquery/chosen/chosen.min.js"></script>
<script src="~/Static/js/zui/zui.min.js"></script>
<script src="~/Static/js/layui/layui.js"></script>
<script src="~/Static/js/layer/layer.js"></script>
<script src="~/Static/js/layer/layer.tools.js"></script>
<style>
    .col-sm-2 {
        width: 14% !important;
    }
</style>
<form method="post" class="form-horizontal" action="/Document_Library/SaveData" id="formLibrary">
    <input type="hidden" name="Id" id="Id" value="@Model.Id">
    <input type="hidden" name="currentMid" id="currentMid" value="@ViewBag.CurrentMid" />
    <input type="hidden" name="FK_Id" id="FK_Id" value="@Model.FK_Id" />
    <input type="hidden" id="secondMenuId" name="secondMenuId" value="@ViewBag.SecondMenuId" />

    <div class="form-group" style="padding-top:16Px;" id="div_DType">
        <label for="DType" class="col-sm-2">文档库类型</label>
        <div class="col-md-6 col-sm-10">
            <input type="hidden" name="DType" value="20" class="form-control" />
            <input type="text" value="公司文档库" class="form-control" readonly />
        </div>
    </div>
    <div id="DName" class="form-group">
        <label for="EndTime" class="col-sm-2">
            文档库名称
        </label>
        <div class="col-md-6 col-sm-10">
            <div class="input-group">
                <input type="text" name="DName" value="@Model.DName" placeholder="文档库名称" class="form-control">
                <input type="hidden" id="IsPrivate" name="IsPrivate" value="@Model.IsPrivate" class="form-control">
                <label class="input-group-addon">
                    @{
                        if (Model.IsPrivate.ToInt() == 1)
                        {
                            <input type="checkbox" id="IsPrivateBox" checked>
                        }
                        else
                        {
                            <input type="checkbox" id="IsPrivateBox">
                        }
                    }
                    设为私密
                </label>
            </div>
        </div>
    </div>
    <div id="div_AuthUserAccount" class="form-group">
        <label for="AuthUserAccount" class="col-sm-2">
            授权用户
        </label>
        <input type="hidden" id="AuthUserAccount" name="AuthUserAccount" class="form-control" value="@Model.AuthUserAccount" placeholder="授权用户">
        <div class="col-md-6 col-sm-10">
            <select data-placeholder="选择用户..." class="chosen-select form-control" tabindex="2" multiple="">
                @{
                    if (ViewBag.AuthUserList != null)
                    {
                        foreach (var item in ViewBag.AuthUserList as IEnumerable<SelectListItem>)
                        {
                            bool bl = true;
                            if (Model.AuthUserAccount.IsNotNullOrEmpty())
                            {
                                List<string> AuthUserList = Model.AuthUserAccount.Split(',').ToList();

                                if (AuthUserList.Contains(item.Value))
                                {
                                    <option value="@item.Value" data-keys="@item.Value" selected>@item.Text</option>
                                    bl = false;
                                    continue;
                                }
                            }

                            if (bl)
                            {
                                <option value="@item.Value" data-keys="@item.Value"> @item.Text </option>
                            }
                        }
                    }
                }
            </select>
        </div>
    </div>
    <div class="form-group" id="div_AuthDept">
        <input type="hidden" id="AuthDept" name="AuthDept" value="@Model.AuthDept" placeholder="授权部门" class="form-control">
        <label for="deptList" class="col-sm-2">
            授权部门
        </label>
        <div class="col-md-6 col-sm-10">
            <label class="checkbox-inline">
                <input type="checkbox" onclick="allDeptCheckClick(this)">全选
            </label>
            @{
                List<Sys_Dept> deptList = ViewBag.DeptList;
                if (deptList != null)
                {
                    foreach (var item in deptList)
                    {
                        bool bl = true;
                        if (!Model.AuthDept.IsNullOrEmpty())
                        {
                            List<string> authDept = Model.AuthDept.Split(',').ToList();
                            if (authDept.Contains(item.Id.ToString()))
                            {
                                <label class="checkbox-inline">
                                    <input type="checkbox" name="visitorsDeptList" value="@item.Id" id="whitelist+@item.Id" onclick="deptCheckBoxOC()" checked> @item.DName
                                </label>
                                bl = false;
                                continue;
                            }
                        }
                        if (bl)
                        {
                            <label class="checkbox-inline">
                                <input type="checkbox" name="visitorsDeptList" value="@item.Id" id="whitelist+@item.Id" onclick="deptCheckBoxOC()"> @item.DName
                            </label>
                        }

                    }
                }
            }
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            @Html.Raw(ViewBag.CurrentBtnList29)
        </div>
    </div>
</form>
<script type="text/javascript">

    $('select.chosen-select').chosen({
        no_results_text: '没有找到',    // 当检索时没有找到匹配项时显示的提示文本
        disable_search_threshold: 10, // 10 个以下的选择项则不显示检索框
        search_contains: true,     // 从任意位置开始检索
    });

    $('select.chosen-select').on('change', function () {
        // 用户改变了选择
        $("#AuthUserAccount").val($(this).val());
    });

    //部门复选框单击事件
    function deptCheckBoxOC() {
        var visitorsList = "";
        $("input:checkbox[name='visitorsDeptList']:checked").each(function () {
            visitorsList += $(this).val() + ",";
        });
        if (visitorsList.length > 0) {
            $("#AuthDept").val(visitorsList.substring(0, visitorsList.length - 1));
        } else {
            $("#AuthDept").val("");
        }
    }

    function saveData() {
        $("#formLibrary").submit();
    }

    $("#formLibrary").Validform({
        tiptype: 3,
        callback: function (form) {
            $("#formLibrary").ajaxSubmit(function (data) {
                if (data.Code == 300) {
                    win.alert(data.Message);
                } else if (data.Code == 200) {
                    win.success("保存成功", function () {
                        window.parent.location.reload();//刷新当前页面.
                        win.close();
                    });
                }
            });
            return false;
        }
    });

    //是否设为私密处理事件
    $("#IsPrivateBox").change(function () {

        if ($(this).is(':checked')) {
            $("#div_AuthRole").hide();
            $("#div_AuthUserAccount").hide();
            $("#AuthUserAccount").val("");
            $("#AuthRole").val("");
            $("#IsPrivate").val("1");
        } else {
            $("#div_AuthRole").show();
            $("#div_AuthUserAccount").show();
            $("#IsPrivate").val("0");
        }
    });

    //部门全选
    function allDeptCheckClick(obj) {
        $("input[name='visitorsDeptList']").prop('checked', $(obj).prop('checked'));
        deptCheckBoxOC();
    }

    function goBack() {
        window.history.go(-1);
    }
</script>